package cn.gemiman.daoyi.module.cms.dal.mysql.blogmessage;

import java.util.*;

import cn.gemiman.daoyi.framework.common.pojo.PageResult;
import cn.gemiman.daoyi.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.gemiman.daoyi.framework.mybatis.core.mapper.BaseMapperX;
import cn.gemiman.daoyi.module.cms.dal.dataobject.blogmessage.BlogMessageDO;
import org.apache.ibatis.annotations.Mapper;
import cn.gemiman.daoyi.module.cms.controller.admin.blogmessage.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 留言 Mapper
 *
 * @author 道一源码
 */
@Mapper
public interface BlogMessageMapper extends BaseMapperX<BlogMessageDO> {

    default PageResult<BlogMessageDO> selectPage(BlogMessagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BlogMessageDO>()
                .eqIfPresent(BlogMessageDO::getAppSiteId, reqVO.getAppSiteId())
                .eqIfPresent(BlogMessageDO::getAppId, reqVO.getAppId())
                .eqIfPresent(BlogMessageDO::getUserType, reqVO.getUserType())
                .eqIfPresent(BlogMessageDO::getUserId, reqVO.getUserId())
                .likeIfPresent(BlogMessageDO::getUserNickname, reqVO.getUserNickname())
                .eqIfPresent(BlogMessageDO::getTag, reqVO.getTag())
                .eqIfPresent(BlogMessageDO::getMessage, reqVO.getMessage())
                .eqIfPresent(BlogMessageDO::getReferTo, reqVO.getReferTo())
                .eqIfPresent(BlogMessageDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BlogMessageDO::getApproveStatus, reqVO.getApproveStatus())
                .eqIfPresent(BlogMessageDO::getViewTimes, reqVO.getViewTimes())
                .eqIfPresent(BlogMessageDO::getThumbsUpTimes, reqVO.getThumbsUpTimes())
                .eqIfPresent(BlogMessageDO::getCreatorIp, reqVO.getCreatorIp())
                .eqIfPresent(BlogMessageDO::getCreatorCity, reqVO.getCreatorCity())
                .betweenIfPresent(BlogMessageDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BlogMessageDO::getId));
    }

    @Update("update cms_blog_message set thumbs_up_times = thumbs_up_times + 1 where id = #{id}")
    void updateThumbsUpTimes(@Param("id") Long id);
}
